cmake_minimum_required(VERSION 3.1.3)

### 判断是否交叉编译
if (CMAKE_TOOLCHAIN_FILE)
    # 交叉编译
    message(STATUS " >>> Cross compiler")
    # run on imx6ul
    add_definitions(-D__ON_IMX6UL__)
else ()
    # 普通编译
    message(STATUS " >>> Normal compiler")
    # run on x86
    add_definitions(-D__ON_X86__)
endif ()

### 系统兼容性检测
if (APPLE)
    # macOS
    message(STATUS " >>> APPLE")
elseif (CYGWIN)
    message(STATUS " >>> CYGWIN")
elseif (UNIX)
    # Linux
    message(STATUS " >>> UNIX")
endif ()

project(libevent_socket_wrapper C)

set(CMAKE_C_STANDARD 11)


# 设置头文件搜索目录
include_directories(./src)
include_directories(./test)
# 查找目录下的所有源文件
# 并将名称保存到 SRCS_XXX 变量
aux_source_directory(./src SRCS_FILES)


set(LINK_LIBS -lpthread -lssl -lcrypto)
set(LINK_LIBS ${LINK_LIBS} -levent -levent_openssl -levent_pthreads)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=leak")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
# 添加链接库


# tcp client单元测试
add_executable(test_tcp_client
               ${SRCS_FILES}
               test/test_tcp_client.c)

target_link_libraries(test_tcp_client ${LINK_LIBS})

# tcp server单元测试
add_executable(test_tcp_server
               ${SRCS_FILES}
               test/test_tcp_server.c)

target_link_libraries(test_tcp_server ${LINK_LIBS})